import { Controller } from "../../mvc/core/Controller";
import { IView } from "../../mvc/interfaces/IView";
import { DominionWarModule } from "../../../modules/DominionWarModule";
import { DominionWarHintBtn } from "../view/dominionWar/DominionWarHintBtn";
import { ResFileConst } from "../resource/ResFileConst";
import { Dispatcher } from "../../mvc/core/Dispatcher";
import { EventName } from "../mvc/EventName";
import { NetDispatcher } from "../../mvc/core/NetDispatcher";
import { EPublicCommand } from "../../../Message/Command/EPublicCommand";
import { DataEvent } from "../events/DataEvent";
import { ConstConfig } from "../resource/ConstConfig";
import { MsgManager } from "../manager/MsgManager";
import { Language } from "../../../extend/language/Language";
import { GameProxy } from "../mvc/GameProxy";
import { MessageBlock } from "../../../Framework/MQ/MessageBlock";
import { SDominionBattleInfo } from "../../../Message/Public/SDominionBattleInfo";
import { SDominionWillOpenNote } from "../../../Message/Public/SDominionWillOpenNote";
import { SDominionInfo } from "../../../Message/Public/SDominionInfo";
//class DominionWarController
    
    export  class DominionWarController extends Controller
    {
       

        protected /* override */ initView(): IView
        {
            if (!this._view) 
            {
                this._view = new DominionWarModule();
            }
            return this._view;
        }

        /* internal  */get module(): DominionWarModule
        {
            return this.initView() as DominionWarModule;
        }

        /* internal  */get icoBtn(): DominionWarHintBtn
        {
            if (!this._icoBtn) 
            {
                this._icoBtn = new DominionWarHintBtn(ResFileConst.DominionWarHintBtn);
            }
            return this._icoBtn;
        }

        protected /* override */ initServer(): void
        {
            Dispatcher.addEventListener(EventName.OnDominionUIOpen, this.onDominionOpen);
            Dispatcher.addEventListener(EventName.ToEnterDomWarCopy, this.toEnterDomWarCopy);
            Dispatcher.addEventListener(EventName.EnterDomWarCopy, this.onEnterDomWarCopy);
            NetDispatcher.addCmdListener(EPublicCommand._ECmdPublicGetDominionBattleInfo, this.onDomBattleInfo);
            NetDispatcher.addCmdListener(EPublicCommand._ECmdPublicDominionWillOpen, this.onBattleLogoShow);
            NetDispatcher.addCmdListener(EPublicCommand._ECmdPublicDominionOpen, this.onDomBattleOpen);
            NetDispatcher.addCmdListener(EPublicCommand._ECmdPublicDominionClose, this.onDomBattleClose);
            return;
        }

        /* internal  */onDomBattleClose(arg1=null): void
        {
            this.icoBtn.hide();
            this.module.hide();
            return;
        }

        /* internal  */onEnterDomWarCopy(arg1: DataEvent): void
        {
            if (this.module) 
            {
                this.module.hide();
            }
            return;
        }

        /* internal  */toEnterDomWarCopy(arg1): void
        {
            var loc1=parseInt(cache.role.combatCapabilities);
            var loc2=cache.role.roleInfo.level;
            var loc3=ConstConfig.instance.getObjectByName("DominionLimit");
            if (loc2 < loc3.constValue) 
            {
                MsgManager.showRollTipsMsg(Language.getStringByParam(27915, loc3.constValue));
            }
            else if (loc1 < loc3.constValueEx) 
            {
                MsgManager.showRollTipsMsg(Language.getStringByParam(27916, loc3.constValueEx));
            }
            else 
            {
                GameProxy.copy.enterDominion();
            }
            return;
        }

        /* internal  */onDomBattleOpen(arg1: MessageBlock): void
        {
            var loc1=arg1.messageBase as SDominionBattleInfo;
            this.cache.dominion.battleInfo = loc1;
            this.cache.dominion.isBattleOpen = true;
            this.icoBtn.show();
            return;
        }

        /* internal  */onBattleLogoShow(arg1: MessageBlock): void
        {
            var loc1=arg1.messageBase as SDominionWillOpenNote;
            this.cache.dominion.willOpenNoteInfo = loc1;
            this.icoBtn.show();
            return;
        }

        /* internal  */onDomBattleInfo(arg1: SDominionInfo): void
        {
            var loc1=null;
            if (cache.dominion.isBattleOpen && this.module) 
            {
                loc1 = cache.dominion.getServerList();
                if (this.module.isHide) 
                {
                    this.module.show();
                }
                this.module.update(loc1);
            }
            return;
        }

        /* internal  */onDominionOpen(arg1: DataEvent): void
        {
            if (cache.dominion.isBattleOpen) 
            {
                GameProxy.copy.getDominionInfo();
            }
            else 
            {
                MsgManager.showRollTipsMsg(Language.getString(90609));
            }
            return;
        }

        private /* var */_icoBtn: DominionWarHintBtn;
    }
